import { Request, Response } from "express";
import { getPostByUser, creatPost } from '../models/postsModel';

// 创建作品 
export const creatPosts = async (req: Request, res: Response) => {
    console.log('reqBody', req.body)
    const { user_id, title, content, image_urls } = req.body;
    if (!user_id || !title || !content || !image_urls) {
        res.status(500).json({
            success: false,
            message: '请输入完整的数据'
        });
    }
    try {
        const post = await creatPost(user_id, title, content, image_urls);

        if (post) {
            res.status(201).json({
                success: true,
                data: post
            });
        } else {
            res.status(500).json({
                success: false,
                message: '作品创建失败'
            });
        }
    } catch (error) {
        console.error('创建作品时出错:', error);
        res.status(500).json({
            success: false,
            message: '服务器错误'
        });
    }
};